package org.example;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.example.collectors.po.Order;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ListTo {

    public static void main(String[] args) {
        // streamFilter();
        // streamMap();
        streamPeek();
    }

    // mapToInt
    // mapToLong
    // mapToDouble
    private static void streamMap() {
        List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
        // 获取对应的平方数
        List<Integer> squaresList = numbers.stream().map(i -> i * i).distinct().collect(Collectors.toList());
    }

    private static void streamFilter() {
        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl");
        // 获取空字符串的数量
        long count = strings.stream().filter(String::isEmpty).count();
    }

    private static void streamFlatMap() {
        List<Order> orderList = new ArrayList<>();
        orderList.stream().flatMap(order -> order.getOrderItems().stream()).collect(Collectors.toList());
    }

    private static void streamPeek() {
        Stream.of("one", "two", "three", "four").filter(e -> e.length() > 3).peek(e -> log.info("filter value {}", e))
            .map(String::toUpperCase).peek(e -> log.info("map value {}", e)).distinct().collect(Collectors.toList());
    }

}
